# -*- coding: utf-8 -*-#
#-------------------------------------------------------------------------------
# 建立者:        博智科技  
# Name:         demo1765
# Description:  爬虫异步IO阻塞切换
# Author:       yzl
# Date:         2019-03-11
#-------------------------------------------------------------------------------

# from urllib import request
import requests
import gevent,time
from gevent import monkey

monkey.patch_all()   #将程序中所有IO操作做上标记使程序非阻塞状态
def url_request(url):
    print('get:%s'%url)
    resp = requests.get(url)
    data = resp.text
    print('%s bytes received from %s'%(len(data),url))

async_time_start = time.time() #开始时间
gevent.joinall([
    gevent.spawn(url_request,'https://www.sina.com.cn/'),
    gevent.spawn(url_request,'https://www.baidu.com/'),
    gevent.spawn(url_request,'https://www.thinkphp.cn')
])
print('耗时:',time.time()-async_time_start) #总用时

